Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression, planner: make the Value field of the Constant struct private | tidb-test=pr/2355 #54244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

Issue Number: close #53504

Problem Summary:

Using .Value directly can easily cause wrong result and dangerous bug, especially for plan cache. We have found #53504 #53505 (and potentially many others). It's not possible to depend on test cases to avoid making mistakes in the future. Therefore, I propose to make .Value private.

What changed and how does it work?

However, it's not simple to make .Value private, because:

  1. The Constant is always constructed directly, like Constant{Value:..., ...}. If we avoid using .Value directly, all these codes need to be changed.
  2. The expression pkg is too big, and we also need to ensure the codes in expression pkg cannot access the .Value. However, golang allows the codes in the same package to access the private field.

Therefore, I wrote a linter to filter out all selector expression to get the .Value.

It's also hard to keep the correctness. I've considered the following three situations:

  1. I just want to get the .Value field, and I'm sure it's not a parameter and deferred function.
  2. I want to get the .Value field. If the current context is not in plan cache, evaluating parameter and deferred function is also fine.
  3. I want to evaluate the parameter, deferred function, or simply return the value.

For most of the codes in optimizing stage, it should call 2. For the code in executing stage, it usually should call 3. We provide GetValue(), GetValueWithoutOverOptimization(), and .Eval for these three circumstances.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix the issue that in some situation, the result is different if the query is using plan cache.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-tests-checked sig/planner SIG: Planner labels Jun 26, 2024
Copy link

ti-chi-bot bot commented Jun 26, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hawkingrei, xuhuaiyu for approval, ensuring that each of them provides their approval before proceeding. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 26, 2024
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

Attention: Patch coverage is 23.16716% with 262 lines in your changes missing coverage. Please review.

Project coverage is 50.8441%. Comparing base (1469fcf) to head (8a1cd57).
Report is 936 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54244         +/-   ##
=================================================
- Coverage   74.7940%   50.8441%   -23.9499%     
=================================================
  Files          1523       1643        +120     
  Lines        361510     608416     +246906     
=================================================
+ Hits         270388     309344      +38956     
- Misses        71504     275391     +203887     
- Partials      19618      23681       +4063     
Flag Coverage Δ
integration 23.0266% <23.1671%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 55.1994% <ø> (ø)
parser ∅ <ø> (∅)
br 48.6053% <ø> (+0.6375%) ⬆️

@YangKeao YangKeao changed the title expression, planner: make the Value field of the Constant struct private expression, planner: make the Value field of the Constant struct private | tidb-test=pr/2355 Jun 27, 2024
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
Copy link

ti-chi-bot bot commented Jun 27, 2024

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/needs-tests-checked label, please finished the tests then check the finished items in description.

For example:

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

📖 For more info, you can check the "Contribute Code" section in the development guide.

Copy link

tiprow bot commented Jun 27, 2024

@YangKeao: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow 8a1cd57 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Jun 27, 2024

@YangKeao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-mysql-client-test 8a1cd57 link true /test pull-mysql-client-test
idc-jenkins-ci-tidb/mysql-test 8a1cd57 link true /test mysql-test
idc-jenkins-ci-tidb/check_dev 8a1cd57 link true /test check-dev
idc-jenkins-ci-tidb/unit-test 8a1cd57 link true /test unit-test
idc-jenkins-ci-tidb/check_dev_2 8a1cd57 link true /test check-dev2

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2024
Copy link

ti-chi-bot bot commented Jul 5, 2024

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Jul 5, 2024
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/needs-tests-checked needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query returns error if using plan cache
2 participants